package main

import (
	"fmt"
	"time"
)

type ListNode struct {
	Val  int
	Next *ListNode
}

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func deleteDuplicates(head *ListNode) *ListNode {
	if head == nil {
		return head
	}
	//下一个是否和自己相同，相同就删除，不同就下一个
	p := head
	for nil != p {
		for nil != p.Next && p.Val == p.Next.Val {
			p.Next = p.Next.Next
		}
		p = p.Next
	}
	return head
}

func main() {
	start := time.Now()
	node := ListNode{1, nil}
	node1 := ListNode{1, nil}
	node2 := ListNode{2, nil}
	link1 := &node
	node.Next = &node1
	node1.Next = &node2
	dec := deleteDuplicates(link1)
	cost := time.Since(start)
	for nil != dec {
		fmt.Println(dec.Val)
		dec = dec.Next
	}
	fmt.Println(cost)
}
